﻿using School;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace SchoolTest
{
    [TestClass()]
    public class CourseTest
    {
        [TestMethod()]
        public void CourseConstructorTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            Assert.AreEqual(name, target.Name);
            Assert.AreEqual(30, Course.MaxSize);
            Assert.AreEqual(0, target.StudentCount);
        }

        [TestMethod()]
        public void AddStudentNormalTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            HashSet<Student> students = new HashSet<Student>();
            for (int i = 10000; i < 10030; i++)
            {
                Student student = new Student(i + " ", i);
                students.Add(student);
                target.AddStudent(student);
            }
            IEnumerable<Student> courseStudents = target.AttendingStudents;
            Assert.AreEqual(30, target.StudentCount, "Number of total students differs!");
            foreach (Student student in courseStudents)
            {
                Assert.IsTrue(students.Contains(student));
            }
        }

        [TestMethod()]
        [ExpectedException(typeof(OverflowException))]
        public void AddStudentOverflowTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            for (int i = 10000; i < 10031; i++)
            {
                Student student = new Student(i + " ", i);
                target.AddStudent(student);
            }
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void AddStudentDuplicateTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            target.AddStudent(new Student("Niki", 80324));
            target.AddStudent(new Student("Niki", 80324));
        }

        [TestMethod()]
        public void RemoveStudentNormalTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            target.AddStudent(new Student("Niki", 80324));
            target.RemoveStudent(new Student("Niki", 80324));
            Assert.AreEqual(0, target.StudentCount, "Student not removed");
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RemoveStudentTest()
        {
            string name = "TestCourse";
            Course target = new Course(name);
            target.RemoveStudent(new Student("Niki", 80324));
        }
    }
}
